import { RootState } from './types'
import { GetterTree, Getter } from 'vuex'
import { UserType } from '@/models/types'

const isLogin: Getter<RootState, RootState> = (state: RootState) => !!state.user.token
const token: Getter<RootState, RootState> = (state: RootState) => state.user.token
const isGetUser: Getter<RootState, RootState> = (state: RootState) => !!state.user.name
const userName: Getter<RootState, RootState> = (state: RootState) => state.user.name
const isSuperAdmin: Getter<RootState, RootState> = (state: RootState) => state.user.type === UserType.SUPER_ADMIN
const userType: Getter<RootState, RootState> = (state: RootState) => state.user.type
const enums: Getter<RootState, RootState> = (state: RootState) => state.app.enums
const currentProject: Getter<RootState, RootState> = (state: RootState) => state.app.project

const getterTree: GetterTree<RootState, RootState> = {
  isLogin,
  isGetUser,
  userName,
  isSuperAdmin,
  enums,
  currentProject,
  userType,
  token
}

export default getterTree
